﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class EventManager  
{
    public delegate void HandlerFunc(object param0, object param1);
    Dictionary<string,List<EventHandler>> Events = new Dictionary<string,List<EventHandler>>();
     
    public void AddHandler(string eventName,HandlerFunc fn)
    {
        EventHandler handler = new EventHandler(eventName, fn);
        if (!Events.ContainsKey(eventName)) 
        {
            Events.Add(eventName,new List<EventHandler>());  
        }
        Events[eventName].Add(handler);
    }

    public void CallEvent(string eventName,object param0=null,object param1=null)
    {
        if (Events.ContainsKey(eventName))  
        {
          foreach(EventHandler handler in Events[eventName])
          {
              handler.Fn(param0,param1);
          }
        }
    
    }
}

public class EventHandler 
{
    public string EventName;
    public EventManager.HandlerFunc Fn;
    public EventHandler(string eventName,EventManager.HandlerFunc fn)
    {
        EventName = eventName;
        Fn = fn;
    }
} 
